<?php

class App_Model_Role extends Ext_Db_Table  
{
    public function getUserRoleId($userId)
    {
        $appModelDbTableUser = Ext_Singleton::getInstance("App_Model_DbTable_User");
        $userRow = $appModelDbTableUser->getRowById($userId);

        if(isset($userRow['roleId']) && $userRow['roleId']>0)
        {
            return $userRow['roleId'];
        }
    
        return 1;
    }
    
    public function getRoleFamilies($roleId, &$roleFamilies)
    {
        $roleRow = App_Model_DbTable_Acl_Role::getInstance()->getRowById($roleId);
        
        $roleFamilies[] = $roleRow;
            
        if(isset($roleRow['parentId']) && $roleRow['parentId'] > 0)
        {
            $this->getRoleFamilies($roleRow['parentId'], $roleFamilies);
        }
           
        return $roleFamilies;
    }
    
    public function getRoleFamilyIds($roleId)
    {
        $roleFamilyArray = $roleFamilyIdArray = array();
        $this->getRoleFamilies($roleId, $roleFamilyArray);
        $roleFamilyArray = array_reverse($roleFamilyArray);
        for($i=0;$i<count($roleFamilyArray);$i++)
        {
            $_roleId = $roleFamilyArray[$i]['id'];
            $roleFamilyIdArray[] = $_roleId;
        }
        
        return $roleFamilyIdArray;
    }
}

